#ifndef EGG_IMAGEUTIL_H
#define EGG_IMAGEUTIL_H

#include "GraphicDevice.h"
#include <opencv2/opencv.hpp>

namespace egg{

    enum Image2DLoadOption{
        ILO_POWER2=0x1,
        ILO_FLIPY=0x2,
    };

    enum Image2DSaveOption{
        ISO_FLIPY=0x1,
    };

    class Image2D{
    public:
        Image2D(const Image2D& _other,bool _copy);
        Image2D(PixelFormat _format,uint32 _w,uint32 _h);
        Image2D(PixelFormat _format,uint32 _w,uint32 _h,byte* _pixels);
        Image2D(const string& _fileName,uint32 _loadOption);
        ~Image2D();
    public:
        void flipY();
        void makePower2();
        void blitFrom(Image2D& _other);
        void saveToFile(const string& fileName,uint32 saveOption);

        inline byte* getPixel(uint32 _x,uint32 _y){
            return &mPixels[(_y*mWidth+_x)*mPixelSize];
        }
        inline byte* getRow(uint32 _index){
            return &mPixels[_index*mPixelSize*mWidth];
        }
        inline uint32 getRowLength(){
            return mPixelSize*mWidth;
        }
        inline uint32 getSize(){
            return mPixelSize*mWidth*mHeight;
        }
    public:
        bool mKeepBuffer;
        byte* mPixels;
        uint32 mWidth;
        uint32 mHeight;
        uint32 mPixelSize;
        PixelFormat mFormat;
    };

}

#endif